package com.java.leetcode;

/**
 * @Author ynb
 * 53. 最大子序和
 * @Date 2021/5/31 17:17
 * @Version 1.0
 */
public class LeetCode053 {
    public int maxSubArray(int[] nums) {
        if (nums.length==1){
            return nums[0];
        }
        int sum =0;
        int result = nums[0];
        for (int i=0;i<nums.length;i++){
            if (sum<0){
                sum=0;
            }
            sum +=nums[i];
            if (result<sum){
                result=sum;
            }
        }
        return  result;
    }

    public static void main(String[] args) {
        LeetCode053 leetCode053 = new LeetCode053();
        System.out.println(leetCode053.maxSubArray(new int []{0}));
    }
}
